<?php
declare (strict_types = 1);

namespace app\api\controller;

use app\api\service\CommonService;
use app\api\service\MessageService;
use think\Response;

class Index
{
    public function index(): Response
    {
        date_default_timezone_set('PRC');
        $params = input('post.');
        set_time_limit(0);
        $message = new MessageService();
        trace($params);
        $ret = $message->initMessage($params);
        return echoJson($ret);
    }

    public function test(){
//        date_default_timezone_set('PRC');
//        $params = input('post.');
//        $message = new CommonService();
//        return echoJson(json_decode($message->get_friend_list('wxid_xmyit5wjvewv22',1),true));
        $url = "https://api.openai.com/v1/completions";
        $params['prompt'] = '写一首诗 关键词 西安';
        $params['max_tokens'] = 2048;
        $params['model'] = 'text-davinci-003';
        $header = [
            "Content-Type: application/json",
            "Accept: application/json",
            "Authorization: Bearer ".env('cg_key')
        ];
        $data = sendHttp($url,json_encode($params),$header,'POST');
        return echoJson(successJson(['content'=>$data['choices'][0]['text']]));
//        if(isset($data['choices']['text'])){
//            return echoJson(successJson(['msg'=>$data['choices']['text']]));
//        }
    }
}
